package com.supermarket.mapper.mapperInpl;

import com.supermarket.mapper.fruitMapper;
import com.supermarket.model.FruitDto;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

@Component
public class fruitMapperImpl implements fruitMapper {

    /**
     * 模拟调用数据库返回水果信息
     *
     * @param fruitName 水果名称
     * @return 水果信息
     */
    @Override
    public FruitDto queryFruitInfo(String fruitName) {
        // 模拟数据库中的值
        List<FruitDto> fruitDtoList = new ArrayList<>();
        FruitDto fruitDto = new FruitDto();
        fruitDto.setFruitName("Strawberry");
        fruitDto.setFruitPrice(new BigDecimal(13));
        fruitDto.setFruitDiscount(new BigDecimal("0.8"));
        fruitDtoList.add(fruitDto);
        fruitDto = new FruitDto();
        fruitDto.setFruitName("Apple");
        fruitDto.setFruitPrice(new BigDecimal(8));
        fruitDto.setFruitDiscount(null);
        fruitDtoList.add(fruitDto);
        fruitDto = new FruitDto();
        fruitDto.setFruitName("Mango");
        fruitDto.setFruitPrice(new BigDecimal(20));
        fruitDto.setFruitDiscount(null);
        fruitDtoList.add(fruitDto);

        // 根据查到的值返回水果信息
        for (FruitDto dto : fruitDtoList) {
            if (dto.getFruitName().equals(fruitName)) {
                return dto;
            }
        }
        return null;
    }
}
